<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <el-form ref="form" :model="detail" label-width="100px" class="form">
        <el-form-item label="标题">
          <el-input v-model="detail.title" />
        </el-form-item>
        <el-form-item label="发布人">
          <el-input v-model="detail.userName" />
        </el-form-item>
		<el-form-item label="性别">
		  <el-radio v-model="detail.personageSex" :label="1">男</el-radio>
		  <el-radio v-model="detail.personageSex" :label="2">女</el-radio>
		</el-form-item>
			<el-form-item label="爱好">
				<el-tag closable :disable-transitions="false" v-for='l in detail.personageHobby' :key='l'>
					{{ l }}
				</el-tag>
			<!-- 	<el-input v-if="inputVisible" ref="saveTagInput" v-model="inputValue" class="input-new-tag" size="small"
				 @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm" /> -->
				<!-- <el-button v-else class="button-new-tag" size="small" @click="showInput">添加爱好</el-button> -->
			</el-form-item>
			<el-form-item label="照片">
			  <div class="picList">
			    <div v-for="(item,index) in detail.personageImage" class="item">
			      <img class="pic" :src="item" alt>
			    </div>
			  </div>
			</el-form-item>
			<el-form-item label="期望室友">
			  <el-input v-model="detail.chumExpect" />
			</el-form-item>
			<el-form-item label="行业">
			  <el-input v-model="detail.personageIndustry" />
			</el-form-item>
			<el-form-item label="室友要求">
			  <el-radio v-model="detail.chumSex" :label="1">男女不限</el-radio>
			  <el-radio v-model="detail.chumSex" :label="2">限男生</el-radio>
			  <el-radio v-model="detail.chumSex" :label="3">限女生</el-radio>
			</el-form-item>
			<el-form-item label="租金">
					 <el-input v-model="detail.monthlyRent" />
			</el-form-item>
			<el-form-item label="地址">
					 <el-input v-model="detail.personageAddress" />
			</el-form-item>
			
			<el-form-item label="公司">
					 <el-input v-model="detail.personageCompany" />
			</el-form-item>
			<el-form-item label="小区">
					 <el-input v-model="detail.community" />
			</el-form-item>
        <el-form-item label="支付方式">
           <el-input v-model="detail.payWay" />
        </el-form-item>
        <el-form-item label="身份">
          <el-radio v-model="detail.identity" :label="1">房东</el-radio>
          <el-radio v-model="detail.identity" :label="2">租客</el-radio>
          <el-radio v-model="detail.identity" :label="3">转租者</el-radio>
        </el-form-item>
        <el-form-item label="户型">
          <el-select v-model="detail.apartmentRype" placeholder="请选择">
            <el-option
              v-for="item in $store.state.user.typeList.filter(item=>item.typeSimplify == 'hou_apartment_type')"
              :key="item.id"
              :label="item.title"
              :value="item.simplify"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="房源描述">
          <el-input   type="textarea"
	        :rows="4"
	        placeholder="请输入..." v-model="detail.describeContent" />
        </el-form-item>
        <el-form-item label="房源照片">
          <div class="picList">
            <div v-for="(item,index) in detail.image" class="item">
              <img class="pic" :src="item" alt>
            </div>
          </div>
          
        </el-form-item>
        
       
        <el-form-item>
          <!-- <el-button type="primary" @click="submit">提交</el-button> -->
          <el-button @click="cancel">返回</el-button>
        </el-form-item>
      </el-form>
    </el-scrollbar>
  </section>
</template>
<script>
import { propertiesList, typeListSon, apartmentAdd, apartmentUpdate,getUcUserLookChumDetail } from '@/api/api'
export default {
  data() {
    return {
      fileList: [],
      buildingTypeOptions: [],
      residentialIdOptions: [],
      salesStatusOptions: [],
	  dynamicTags: [],
	  relatedMatching: [],
	  inputVisible: false,
	  inputValue: '',
      postIdOptions: [
        {
          value: 1,
          label: 'APP端'
        },
        {
          value: 2,
          label: 'PC端'
        }],
      detail: {
      }
    }
  },
  created() {
    // if (this.$route.query.item) {
    //   this.detail = JSON.parse(this.$route.query.item)
    //   this.fileList[0] = this.detail.apartmentPicture
    // }
    // this.getMb()
	getUcUserLookChumDetail({
	 id:this.$route.query.data
	}).then(data => {
	  
	   data.data.personageHobby=data.data.personageHobby.split(",");
	   data.data.image=data.data.image.split(",");
	   data.data.personageImage=data.data.personageImage.split(",");
	   this.detail = data.data
	})
	
  },
  methods: {
	  handleClose(tag) {
	  	this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
	  },
	  handleInputConfirm() {
	  	const inputValue = this.inputValue
	  	if (inputValue) {
	  		this.dynamicTags.push(inputValue)
	  	}
	  	this.inputVisible = false
	  	this.inputValue = ''
	  },
	  showInput() {
	  	this.inputVisible = true
	  	this.$nextTick(_ => {
	  		this.$refs.saveTagInput.$refs.input.focus()
	  	})
	  },
    getMb() {
      // 小区列表
      propertiesList({
        curPage: 1,
        pageSize: 999,
        name: ''
      }).then(data => {
        this.residentialIdOptions = data.data.records
      })
      // 建筑类型
      typeListSon('8e612c9d4a0dc5f7c3ef76df6e394091').then(({ data }) => {
        this.buildingTypeOptions = data
      })
      // 销售类型
      typeListSon('b85139395c06993f94e9fce2b96e9b43').then(({ data }) => {
        this.salesStatusOptions = data
      })
    },
    changeResidentialId(value) {
      const a = this.residentialIdOptions.filter(item => item.id == value)
      this.detail.dataName = a[0].name
    },
    handleRemove(index) {
      this.fileList.splice(index, 1)
    },
    // 上传图片之前的验证
    handleUpload() {
    },
    // 上传成功之后的回调
    handleSuccess(res) {
      if (res.code === 200) {
        this.fileList.push(res.data)
        this.detail.logo = this.fileList[0]
      }
    },
    // 添加/编辑
    submit() {
      // 验证不通过则不提交
      if (!this.vertify()) {
        return false
      }
      if (this.$route.query.item) {
        // 编辑
        apartmentUpdate(this.detail).then(data => {
          Is.tip('编辑成功', 2000, 'success')
          this.$router.back()
        })
      } else {
        // 新增
        apartmentAdd(this.detail).then(data => {
          Is.tip('添加成功', 2000, 'success')
          this.$router.back()
        })
      }
    },
    // 返回
    cancel() {
      this.$router.back()
    },
    vertify() {
      // if (Is.empty(this.detail.title)) {
      //   Is.tip('请输入标题')
      //   return false
      // }
      return true
    }
  }}
</script>
